package com.parktech.sun.web.controller;

import com.parktech.sun.domain.model.Constants;
import com.parktech.sun.domain.model.sunhz.Industry;
import com.parktech.sun.domain.model.sunhz.IndustryCategory;
import com.parktech.sun.domain.repository.Page;
import com.parktech.sun.domain.service.aboutus.AboutUsService;
import com.parktech.sun.domain.service.sunhz.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * User: Think
 * Date: 11-1-18
 * Time: 上午3:25
 */
@Controller
@RequestMapping("/enterprises")
public class EnterpriseViewController extends BaseViewController {

    private int pageSize = Constants.PAGINATION_PAGE_SIZE;

    private EnterpriseService enterpriseService;

    @Autowired
    private AboutUsService aboutUsService;

    @Autowired
    public EnterpriseViewController(EnterpriseService enterpriseService) {
        this.enterpriseService = enterpriseService;
    }

    @RequestMapping("/pages/category/{categoryId}")
    public String viewCategory(@PathVariable("categoryId") int categoryId, Model model) {
        model.addAttribute(aboutUsService.getByCategory("enterpriseIntroduction"));
        model.addAttribute("enterpriseList", enterpriseService.listByCategory(categoryId));
        return "enterpriseProduct";
    }
    @RequestMapping("/pages/{pageNo}")
    public String viewPage(@PathVariable("pageNo") int pageNo, Model model) {
        Page page = new Page(pageSize, pageNo);
        model.addAttribute(aboutUsService.getByCategory("enterpriseIntroduction"));
        model.addAttribute(enterpriseService.pageBy(page));
        return "enterprises";
    }

    @RequestMapping("/{enterpriseId}")
    public String viewDetail(@PathVariable("enterpriseId") Long enterpriseId, Model model) {
        model.addAttribute(enterpriseService.getById(enterpriseId));
        return "enterpriseDetail";
    }

}
